package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.FragmentUtils;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityDateCalculateBinding;
import flc.ast.fragment.date.DateCalFragment;
import flc.ast.fragment.date.DateConvertFragment;
import flc.ast.fragment.date.DateIntervalFragment;

public class DateCalculateActivity extends BaseAc<ActivityDateCalculateBinding> {

    private List<Fragment> mFragmentList;
    private DateCalFragment dateCalFragment;
    private DateConvertFragment dateConvertFragment;
    private DateIntervalFragment dateIntervalFragment;

    @Override
    protected int onCreate() {
        return R.layout.activity_date_calculate;
    }

    @Override
    protected void initView() {
        mDataBinding.ivDateCalculateBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvDateKind1.setOnClickListener(this);
        mDataBinding.tvDateKind2.setOnClickListener(this);
        mDataBinding.tvDateKind3.setOnClickListener(this);

        mFragmentList = new ArrayList<>();

        dateCalFragment = new DateCalFragment();
        dateConvertFragment = new DateConvertFragment();
        dateIntervalFragment = new DateIntervalFragment();

        mFragmentList.add(dateCalFragment);
        mFragmentList.add(dateConvertFragment);
        mFragmentList.add(dateIntervalFragment);

        FragmentUtils.add(getSupportFragmentManager(), mFragmentList, R.id.fl_container, 0);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.tvDateKind1://日期推算
                clearSelection();
                mDataBinding.tvDateKind1.setTextColor(Color.parseColor("#000000"));
                mDataBinding.tvDateKind1.setBackgroundResource(R.drawable.timer_sel);
                FragmentUtils.showHide(0, mFragmentList);
                break;
            case R.id.tvDateKind2://日期转换
                clearSelection();
                mDataBinding.tvDateKind2.setTextColor(Color.parseColor("#000000"));
                mDataBinding.tvDateKind2.setBackgroundResource(R.drawable.timer_sel);
                FragmentUtils.showHide(1, mFragmentList);
                break;
            case R.id.tvDateKind3://日期间隔
                clearSelection();
                mDataBinding.tvDateKind3.setTextColor(Color.parseColor("#000000"));
                mDataBinding.tvDateKind3.setBackgroundResource(R.drawable.timer_sel);
                FragmentUtils.showHide(2, mFragmentList);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void clearSelection() {
        mDataBinding.tvDateKind1.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvDateKind1.setBackground(null);
        mDataBinding.tvDateKind2.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvDateKind2.setBackground(null);
        mDataBinding.tvDateKind3.setTextColor(Color.parseColor("#B2C1CF"));
        mDataBinding.tvDateKind3.setBackground(null);
    }

}